package com.woniuxy.controllers;

import com.woniuxy.remote.RemoteCompanyService;
import com.woniuxy.utils.JWTUtils;
import com.woniuxy.utils.LoginCustomer;
import com.woniuxy.utils.LoginUser;
import com.woniuxy.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class CustomerComplaintController {
    @Autowired
    private JWTUtils jwtUtils;
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private RemoteCompanyService remoteCompanyService;

    @PostMapping("/customerComplaint/list")
    private ResultVO getComplaintsByCid(@RequestBody Map<String,Object> map){
//        Integer pageNum = (Integer) map.get("pageNum");
//        Integer pageSize = (Integer) map.get("pageSize");
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token  = servletRequestAttributes.getRequest().getHeader("token");
        String customerName = jwtUtils.getUsername(token);
        ValueOperations valueOperations = redisTemplate.opsForValue();
        LoginCustomer loginCustomer = (LoginCustomer) valueOperations.get("customer:"+customerName);
        Integer cid = loginCustomer.getCustomer().getCid();
        map.put("cid",cid);
        ResultVO resultVO = remoteCompanyService.getComplaintsByCid(map);
        ResultVO resultVO = remoteCompanyService.getComplaintsByCid(map);
        return resultVO;
    }
}
